package com.wlyuan.open.remote.facade;

import com.wlyuan.open.dto.OpenClientRegisterDTO;
import com.wlyuan.open.remote.facade.translator.TenantTranslator;
import com.wlyuan.tenant.api.ITenantService;
import com.wlyuan.tenant.dto.company.CompanyTenantRegisterDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author lijing
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class TenantFacade {
    private final ITenantService tenantService;

    public Tenant getTenantById(Long tenantId) {
        return TenantTranslator.translate(tenantService.getTenantById(tenantId));
    }

    public Tenant register(OpenClientRegisterDTO register) {
        var creation = new CompanyTenantRegisterDTO();
        BeanUtils.copyProperties(register, creation);
        creation.setContactEmail(register.getEmail());
        creation.setSource(3);
        return TenantTranslator.translate(tenantService.register(creation));
    }
}
